package com.example.worldcupserver1.controller;

import com.example.worldcupserver1.bean.User;
import com.example.worldcupserver1.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
@RestController
public class UserController {
    @Autowired /*让系统创建数据访问层的对象*/
            UserDao userDao;
    Map<String, Object> map = new HashMap<>();
    @RequestMapping("/WorldCupApp/user/regist")
    @ResponseBody  /*返回给客户端的数据的类型为 json格式*/
    public Map<String, Object> register(@RequestBody User user) {
        //注解@RequestBody 请求参数为json格式字符串数据
        User savedUser = userDao.save(user);
        if (savedUser != null) {
            map.put("success", true);
            map.put("msg", "成功");
        } else {
            map.put("success", false);
            map.put("msg", "失败");
        }
        return map;
    }
}
